﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using InTheHand.Net;
using InTheHand.Net.Sockets;
using System.Collections.ObjectModel;
using InTheHand.Net.Bluetooth;

namespace BlueRadar.API
{
    public static class Common
    {
        public static ObservableCollection<Device> SearchDevices(int maxdevices,bool auth,bool remembered,bool unknown,bool discover)
        {
            ObservableCollection<Device> List = new ObservableCollection<Device>();
            BluetoothAddress[] address_array = new BluetoothAddress[1000];
            BluetoothDeviceInfo[] array;
            BluetoothClient bc = new BluetoothClient();
            array = bc.DiscoverDevices(maxdevices,auth,remembered,unknown,discover);

            foreach (BluetoothDeviceInfo info in array)
            {
                List<string> services = GetServiceName(info.InstalledServices);
                List.Add(new Device(info, services));
            }
            return List;
        }

        private static List<string> GetServiceName(Guid[] guid)
        {
            List<string> services = new List<string>();
            foreach (Guid g in guid)
            {
                services.Add(BluetoothService.GetName(g));
            }
            return services;
        }
    }
}
